package com.zh.mycommon.value;

/**
 * 二元组
 * @author ZH
 * @date 18:38 2023/7/31
 */
public record Tuple2<A,B>(A v1, B v2){

    public static <T extends Comparable<T>> Tuple2<T, T> sorted(Tuple2<T, T> tuple) {
        T v1 = tuple.v1();
        T v2 = tuple.v2();

        if (v1.compareTo(v2) > 0) {
            return new Tuple2<>(v2, v1);
        } else {
            return tuple;
        }
    }
}
